package Queue._622_DesignCircularQueue;

import java.util.ArrayList;
import java.util.List;

public class MyCircularQueue {
    /** Initialize your data structure here. Set the size of the queue to be k. */
    List<Integer> queue;
    int len;
    public MyCircularQueue(int k) {
        this.queue = new ArrayList<>();
        this.len = k;
    }

    /** Insert an element into the circular queue. Return true if the operation is successful. */
    public boolean enQueue(int value) {
        if (queue.size() < len) {
            queue.add(value);
            return true;
        } else {
            return false;
        }
    }

    /** Delete an element from the circular queue. Return true if the operation is successful. */
    public boolean deQueue() {
        if (queue.size() == 0) {
            return false;
        } else {
            queue.remove(0);
            return true;
        }
    }

    /** Get the front item from the queue. */
    public int Front() {
        if (queue.size() == 0) {
            return -1;
        } else {
            return queue.get(0);
        }
    }

    /** Get the last item from the queue. */
    public int Rear() {
        if (queue.size() == 0) {
            return -1;
        } else {
            return queue.get(queue.size() - 1);
        }
    }

    /** Checks whether the circular queue is empty or not. */
    public boolean isEmpty() {
        return queue.isEmpty();
    }

    /** Checks whether the circular queue is full or not. */
    public boolean isFull() {
        return queue.size() == len;
    }
}
